



/*  事件链表定义  */

#include "stdio.h"
#include "system_event_list.h"
WindSystemEvent systerm_event_list;
void systerm_event_list_init()
{
    cm_init_list_head(&systerm_event_list.test_list_item);
}


/*      从系统事件链表中获取事件      */
WindSystemEvent *wind_system_event_pop()
{
    struct list_head *pos = NULL;
    struct list_head *n = NULL;
    WindSystemEvent *se = NULL;
    cm_list_each_safe(pos, n, &(systerm_event_list.test_list_item))
    {
        se = cm_list_item(pos, WindSystemEvent, test_list_item);
        if (se)
        {
            printf("pop data: %d, cmd: %d\n", se->info.open_count, se->info.cmd);
            cm_list_del_item(&se->test_list_item);
            return se;
        }
    }
    return NULL;
}


/*      添加系统事件到链表中    */
int wind_system_event_push(int event_type,int open_count,float image_angle)
{
    WindSystemEvent *event = (WindSystemEvent *)malloc(sizeof(WindSystemEvent));
    if (event == NULL) // Check if malloc was successful
    {
        printf("Error: Memory allocation failed for WindSystemEvent");
        return -1; // Return an error code
    }
    event->info.cmd = event_type;
    event->info.open_count = open_count;
    event->info.angle = image_angle;
    printf("add event door close count [%u] angle [%f]\n", open_count, image_angle);
    cm_list_add_tail(&event->test_list_item, &(systerm_event_list.test_list_item));
    return 0;
}
